package com.study.webapp.leetcode;

import java.util.LinkedList;

/**
 * 无重复字符的最长子串
 * 
 * @author admin
 *
 *         2018年10月19日
 */
public class Leet_02 {

	public static void main(String[] args) {
		String langStr = "uqinntq";
		System.out.println(lengStr(langStr));

	}

	public static int lengStr(String s) {
		if (s == null || s.length() == 0) {
			return 0;
		}
		char[] chars = s.toCharArray();
		int sum = 0;
		LinkedList<Character> list = new LinkedList<>();
		for (int i = 0; i< chars.length; i++) {
			if (!list.contains(chars[i])) {
				list.add(chars[i]);
				if (sum<list.size()) {
					sum = list.size();
				}
			} else {
				int index = list.indexOf(chars[i]);
				for (int j = 0; j < index;j++) {
					list.remove();
				}
				list.remove();
				list.add(chars[i]);
			}
		}
		return sum;
	}

}
